<!DOCTYPE html>
<html>
	
<!-- Mirrored from jquerymobile.com/demos/1.0b1/docs/forms/docs-forms.html by HTTrack Website Copier/3.x [XR&CO'2010], Mon, 27 Jun 2011 17:13:59 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8"><!-- /Added by HTTrack -->
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>jQuery Mobile Docs - Forms</title>
	<link rel="stylesheet"  href="../../../../../code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.css" />
	<link rel="stylesheet" href="../assets/css/jqm-docs.css"/>
	<script src="../../../../../code.jquery.com/jquery-1.6.1.min.js"></script>
	<script src="../../experiments/themeswitcher/jquery.mobile.themeswitcher.js"></script>
	<script src="../assets/js/jqm-docs.js"></script>
	<script src="../../../../../code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.js"></script>
</head>
<body>

	<div data-role="page" class="type-interior">

		<div data-role="header" data-theme="f">
		<h1>Forms</h1>
		<a href="../../index.html" data-icon="home" data-iconpos="notext" data-direction="reverse" class="ui-btn-right jqm-home">Home</a>
	</div><!-- /header -->

	<div data-role="content">
		<div class="content-primary">
			<p>jQuery Mobile provides a complete set of finger-friendly form elements that are based on native HTML form elements.</p>

			<h2>Form structure</h2>

			<p>All forms should be wrapped in a <code>form</code> tag that has an <code>action</code> and <code>method</code> that will handle the form data processing on the server.</p>

<code>
&lt;form action=&quot;form.php&quot; method=&quot;post&quot;&gt;
...
&lt;/form&gt;
</code>


<h2>Markup Conventions</h2>
<p>When constructing forms to be used in jQuery Mobile, most of the standard guidelines used to create forms that submit via normal HTTP post or get still apply. However, one thing to keep in mind is that the <code>id</code> attributes of form controls need to be not only unique on a given page, but also unique across the pages in a site. This is because jQuery Mobile's single-page navigation model allows many different "pages" to be present in the DOM at the same time, so you must be careful to use unique <code>id</code> attributes so there will be only one of each in the DOM (and of course, be sure to pair them properly with <code>label</code> elements via the <code>for</code> attribute).</p>

	<h2>Auto-initialization of form elements</h2>
	<p>By default, jQuery Mobile will automatically enhance certain native form controls into rich touch-friendly components. This is handled internally by finding form elements by tag name and running a plugin method on them, so for instance, a <code>select</code> element will be found and initialized with the "selectmenu" plugin, while an <code>input</code> element with a <code>type="checkbox"</code> will be enhanced with the "checkboxradio" plugin. Once initialized, you can address these enhanced components programmatically through their jQuery UI widget API methods (see documentation on available methods here: <a href="plugin-eventsmethods.html">Form Plugin Methods</a>). </p>

	<h2>Preventing auto-initialization of form elements</h2>
	<p>If you'd prefer that a particular form control be left untouched by jQuery Mobile, simply give that element the attribute <code> data-role="none"</code>. For example:</p>
	<pre><code>
&lt;label for=&quot;foo&quot;&gt;
&lt;select name=&quot;foo&quot; id=&quot;foo&quot; <strong> data-role=&quot;none&quot;</strong>&gt;
	&lt;option value="a" &gt;A&lt;/option&gt;
	&lt;option value="b" &gt;B&lt;/option&gt;
	&lt;option value="c" &gt;C&lt;/option&gt;
&lt;/select&gt;
</code></pre>


	<p>Or, if you'd like to prevent auto-initialization without adding attributes to your markup, you can customize the selector that is used for preventing auto-initialization by setting the page plugin's <code>keepNative</code> option (which defaults to <code>[data-role="none"]</code>. Be sure to configure this option inside an event handler bound to the <code>mobileinit</code> event, so that it applies to the first page as well as subsequent pages that are loaded.</p>
		<pre><code>
$(document).bind('mobileinit',function(){
	<strong>$.mobile.page.prototype.options.keepNative = "select, input.foo, textarea.bar";</strong>
});
		</pre></code>

<p>One special case is that of selects. The above sample will prevent any and all augmentation from taking place on select elements in the page if <code>select</code> is included. If you wish to retain the native performance, look/feel of the menu itself and benefit from the visual augmentation of the select button by jQuery Mobile you can set $.mobile.nativeSelectMenu to true in a <code>mobileinit</code> callback as a global setting or use <code>data-native="true"</code> on a case by case basis.</p>

			<h2>Dynamic form layout</h2>

			<p>In jQuery Mobile, all form elements are designed to be a flexible width so they will comfortably fit the width of any mobile device. One optimization built into the framework is that we present labels and form elements differently based on screen width. </p>
			<p>If a page is fairly narrow (~480px), the labels are styled as block-level elements so they will stack on top of the form element to save horizontal space.</p>
			<p>On wider screens, the labels and form elements are styled to be on the same line in a 2-column layout to take advantage of the screen real estate.</p>

			<h2>Field containers</h2>

			<p>To improve the styling to labels and form elements on wider screens, we recommend wrapping a <code>div</code> or <code>fieldset </code>with the <code> data-role="fieldcontain"</code> attribute around each label/form element. The framework will add a thin vertical bottom border on this container to act as a field separator and visually align the label and form elements for quick scanning.</p>

<pre><code>
&lt;div data-role=&quot;fieldcontain&quot;&gt;
	...label/input code goes here...
&lt;/div&gt;
</code></pre>

        <h2>Refreshing form elements</h2>

        <p>Every form control -- where applicable -- has a refresh method. Here are some examples:</p>

<p>Checkboxes:</p>

<code>
$("input[type='checkbox']").attr("checked",true).checkboxradio("refresh");
</code>

<p>Radios:</p>
<code>
$("input[type='radio']").attr("checked",true).checkboxradio("refresh");
</code>

<p>Selects:</p>
<code><pre>
var myselect = $("select#foo");
myselect[0].selectedIndex = 3;
myselect.selectmenu("refresh");
</pre></code>

<p>Sliders:</p>
<code>
$("input[type=range]").val(60).slider("refresh");
</code>

<p>Flip switches (they use slider):</p>

<code><pre>
var myswitch = $("select#bar");
myswitch[0].selectedIndex = 1;
myswitch .slider("refresh");
</pre></code>

<p>We're considering adding a refresh method to forms to let the framework refresh all the individual elemnts withing but that is a future enhancement.</p>

	</div><!--/content-primary -->		
	
	<div class="content-secondary">
		
		<div data-role="collapsible" data-collapsed="true" data-theme="b">
			
				<h3>More in this section</h3>
				
				<ul data-role="listview" data-theme="c" data-dividertheme="d">
				
					<li data-role="list-divider">Form elements</li>
					<li data-theme="a"><a href="docs-forms.html">Form basics</a></li>
					<li><a href="forms-all.html">Form element gallery</a></li>
					<li><a href="forms-text.html">Text inputs</a></li>
					<li><a href="forms-search.html">Search inputs</a></li>
					<li><a href="forms-slider.html">Slider</a></li>
					<li><a href="forms-switch.html">Flip toggle switch</a></li>
					<li><a href="forms-radiobuttons.html">Radio buttons</a></li>
					<li><a href="forms-checkboxes.html">Checkboxes</a></li>
					<li><a href="forms-selects.html">Select menus</a></li>
					<li><a href="forms-themes.html">Theming forms</a></li>
					<li><a href="forms-all-native.html">Native form elements</a></li>
					<li><a href="forms-sample.html">Submitting forms</a></li>
					<li><a href="plugin-eventsmethods.html">Plugin methods</a></li>
	
				</ul>
		</div>
	</div>		

</div><!-- /content -->

<div data-role="footer" class="footer-docs" data-theme="c">
		<p>&copy; 2011 The jQuery Project</p>
</div>
	
</div><!-- /page -->

</body>

<!-- Mirrored from jquerymobile.com/demos/1.0b1/docs/forms/docs-forms.html by HTTrack Website Copier/3.x [XR&CO'2010], Mon, 27 Jun 2011 17:13:59 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8"><!-- /Added by HTTrack -->
</html>
